package com.lucifer.cloud.boot.blog.controller;

import com.lucifer.cloud.boot.blog.domin.dto.ai.ChatDto;
import com.lucifer.cloud.boot.blog.service.AiService;
import com.lucifer.cloud.commons.model.Result;
import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;


/**
 * @author lucifer
 * @date 2024/10/24 17:49
 */
@RestController
@RequestMapping("ai")
public class AiController {

    @Resource
    private AiService aiService;


    @GetMapping("/vec/add")
    public Result vecAdd() {
        aiService.vecAdd();
        return Result.success();
    }

    @GetMapping("/vec/search")
    public Result vecSearch(@RequestParam(value = "query") String query) {
        List<Document> documentList = aiService.vecSearch(query);
        return Result.success(documentList);
    }


    @PostMapping("/vec/saveFile")
    public Result vecSaveFile(@RequestParam(value = "file")MultipartFile file) {
       aiService.saveFile(file);
        return Result.success();
    }

    @GetMapping("/vec/query")
    public Result vecQuery(@RequestParam(value = "query") String query) {
        String queried = aiService.query(query);
        return Result.success(queried);
    }

    @GetMapping("/openAiChat")
    public String OpenAiChat2(@RequestParam(value = "sessionId") String sessionId,
                              @RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        return aiService.dsChat(sessionId, message);
    }


    @PostMapping("/chat")
    public ChatDto zhiPu(@RequestBody Map map) {
        return aiService.zhiPuChat(map);
    }

//    @PostMapping(value = "/ocr", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
//    public String recognition(
//            @RequestParam("file") MultipartFile file
//    ) {
//        return aiService.orc(file);
//    }
//
//    @PostMapping("/mnist-predict")
//    public int predictWithBlackBackground(@RequestParam("file") MultipartFile file, @RequestParam("isNeedRevert") Boolean isNeedRevert) {
//        // 训练模型的时候，用的数字是白字黑底，
//        // 因此如果上传白字黑底的图片，可以直接拿去识别，而无需反色处理
//        return aiService.predict(file, isNeedRevert);
//    }
//
//    @PostMapping("/predict")
//    public String predict(@RequestParam("file") MultipartFile file) {
//        return aiService.predict(file);
//    }

}
